//
//  RecoummendHotelVC.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/23.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "RecoummendHotelVC.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

#import "RecommendHotelTableCell.h"
#import "DataHandler.h"
#import "RecoummendHotelModel.h"

#import "RecoummendHotelDataVC.h"

@interface RecoummendHotelVC ()
@property (nonatomic, strong) UITableView *myTabelView;

@end

@implementation RecoummendHotelVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self getData];
    
    self.myTabelView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.myTabelView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTabelView];
    
    //成为代理人
    self.myTabelView.delegate = self;
    self.myTabelView.dataSource = self;
    
    //注册
//    UINib *nib = [UINib nibWithNibName:@"New_discountTableViewCell" bundle:[NSBundle mainBundle]];
//    [self.myTabelView registerNib:nib forCellReuseIdentifier:discountReuse];
    [self.myTabelView registerClass:[RecommendHotelTableCell class] forCellReuseIdentifier:@"reuse"];
    
    //添加头视图
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 370)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.myTabelView.tableHeaderView = headerView;
    
    [self addHeader];
    
    // Do any additional setup after loading the view.
}

-(void)getData{
    self.myHotelArrayM = [NSMutableArray array];
    
    DataHandler *handler1 = [[DataHandler alloc] init];
    
    [handler1 getRecoummendHotelDataNotes: ^(id result) {
        self.myHotelArrayM = [NSMutableArray arrayWithArray:result];
        [self.myTabelView reloadData];
    } failedHandler:^(NSError *error) {
    }];
}

//自定义头视图
- (void)addHeader{
    //背景图
    UIImageView *bakeImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hotel_bg.jpg"]];
    bakeImage.frame = CGRectMake(0, 0, WIDTH, 370);
    [self.myTabelView addSubview:bakeImage];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(35, 30, WIDTH - 70, 45)];
    label.backgroundColor = [UIColor clearColor];
    label.text = @"全球超过540,000家酒店供你选择";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    [self.myTabelView addSubview:label];
    
    //选择目的地
    UIView *xzmdV = [self addView];
    xzmdV.frame = CGRectMake(35, 30 + 45  + 15 , WIDTH - 70, 45);
    self.xzmddLabel = [self addLabel:@"寻找目的地"];
    self.xzmddLabel.frame = CGRectMake(55, 30 + 45  + 15 , WIDTH - 140, 45);
    UILabel *fuhao = [self addLabel:@">"];
    fuhao.frame = CGRectMake(WIDTH - 55, 30 + 45  + 15 , 10, 45);
    self.XZMDDButton = [self addButton];
    self.XZMDDButton.frame = CGRectMake(35, 30 + 45  + 15 , WIDTH - 70, 45);
    [self.XZMDDButton addTarget:self action:@selector(XZMDDButtonAction) forControlEvents:UIControlEventTouchUpInside];
    //入住日期
    UIView *dateV = [self addView];
    dateV.frame = CGRectMake(35, 150, WIDTH  - 70, 125);
    self.checkinDateLabel = [self addLabel:@"入住日期"];
    self.checkinDateLabel.textAlignment = NSTextAlignmentCenter;
    self.checkinDateLabel.textColor = [UIColor colorWithRed:111 / 255.0 green:124 / 255.0 blue:235 / 255.0 alpha:1.0];
    self.checkinDateLabel.frame = CGRectMake(35, 160, WIDTH / 2 - 35, 30);
    
    //获取当前日期
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY年MM月dd日>"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];

    NSString *inWeek = @"周一";
    self.checkinDateInputWeekLabel = [self addLabel:inWeek];
    self.checkinDateInputWeekLabel.textAlignment = NSTextAlignmentCenter;
    self.checkinDateInputWeekLabel.frame = CGRectMake(35, 190, WIDTH / 2 - 35, 30);

    self.checkinDateInputDateLabel = [self addLabel:dateString];
    self.checkinDateInputDateLabel.textAlignment = NSTextAlignmentCenter;
    self.checkinDateInputDateLabel.frame = CGRectMake(35, 220, WIDTH / 2 - 35, 30);
    
    //离开日期
    self.checkOutDateLabel = [self addLabel:@"离开日期"];
    self.checkOutDateLabel.textAlignment = NSTextAlignmentCenter;
    self.checkOutDateLabel.textColor = [UIColor colorWithRed:111 / 255.0 green:124 / 255.0 blue:235 / 255.0 alpha:1.0];
    self.checkOutDateLabel.frame = CGRectMake(WIDTH / 2, 160, WIDTH / 2 - 35, 30);
    NSString *outWeek = @"周四";
    self.checkOutDateInputWeekLabel = [self addLabel:outWeek];
    self.checkOutDateInputWeekLabel.textAlignment = NSTextAlignmentCenter;
    self.checkOutDateInputWeekLabel.frame = CGRectMake(WIDTH / 2, 190, WIDTH / 2 - 35, 30);
    self.checkOutDateInputDateLabel = [self addLabel:dateString];
    self.checkOutDateInputDateLabel.textAlignment = NSTextAlignmentCenter;
    self.checkOutDateInputDateLabel.frame = CGRectMake(WIDTH / 2, 220, WIDTH / 2 - 35, 30);
    //按钮
    self.checkInDateButton = [self addButton];
    self.checkInDateButton.frame = CGRectMake(35, 150, WIDTH / 2 - 35, 125);
    self.checkOutDateButton = [self addButton];
    self.checkOutDateButton.frame = CGRectMake(WIDTH / 2, 150, WIDTH / 2 - 35, 125);
    
    //查找酒店
    self.CZJDButton = [self addButton];
    [self.CZJDButton setTitle:@"🔍 查找酒店" forState:UIControlStateNormal];
    self.CZJDButton.frame = CGRectMake(35, 300, WIDTH - 70, 40);
    [self.CZJDButton setTitleColor: [UIColor whiteColor] forState:UIControlStateNormal];
    self.CZJDButton.backgroundColor = [UIColor colorWithRed:111 / 255.0 green:124 / 255.0 blue:235 / 255.0 alpha:1.0];
    self.CZJDButton.alpha = 1.0;
    
    
}
//button点击方法
- (void)XZMDDButtonAction{
    RecoummendHotelDataVC *dataVC = [[RecoummendHotelDataVC alloc] init];
    [self.navigationController pushViewController:dataVC animated:YES];
}


- (UIView *)addView{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 5;
    view.alpha = 0.5;
    [self.myTabelView addSubview:view];
    return view;
}

- (UILabel *)addLabel:(NSString *)text{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.text = text;
    label.font = [UIFont systemFontOfSize:14];
    [self.myTabelView addSubview:label];
    return label;
    
}
- (UIButton *)addButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 5;
    [button setTitleColor: [UIColor grayColor] forState:UIControlStateNormal];
    [self.myTabelView addSubview:button];
    return button;
 
}

//分区的个数
-(NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//分区头高度
-(CGFloat )tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 50;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{ //背景颜色
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor whiteColor];
    
    //标题
    UILabel *CKQB = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH , 50)];
    CKQB.text = @"热门城市酒店";
    CKQB.textColor = [UIColor grayColor];
    CKQB.textAlignment = NSTextAlignmentCenter;
    CKQB.font = [UIFont systemFontOfSize:15];
    [view addSubview:CKQB];
    return view;
}

//cell高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 430;
}

//cell数
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

//建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RecommendHotelTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.myHotelArrayM= self.myHotelArrayM;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
